package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.WebCatalogDao;
import ysq.xyg.model.WebCatalog;
import ysq.xyg.service.WebCatalogService;

import javax.annotation.Resource;
import java.util.List;


@Service("webCatalogService")
public class WebCatalogServiceImpl extends BaseServiceImpl<WebCatalog> implements WebCatalogService {

    @Resource
    private WebCatalogDao webCatalogDao;
    @Autowired
    public void setpictureDao(WebCatalogDao webCatalogDao) {
        this.baseDao = webCatalogDao;
    }

    @Override
    public PageInfo<WebCatalog> page(WebCatalog webCatalog, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy("sort desc");
        return new PageInfo<WebCatalog>(list(webCatalog));
    }

    @Override
    public List<WebCatalog> list(WebCatalog webCatalog) {
        // 通用Example查询
        Example example = new Example(WebCatalog.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(webCatalog.getType())) {
            criteria.andEqualTo("type", webCatalog.getType());
        }
        if (StringUtils.isNotEmpty(webCatalog.getName())) {
            criteria.andLike("name", "%"+webCatalog.getName()+"%");
        }
        example.setOrderByClause("sort desc");
        List<WebCatalog> list = webCatalogDao.selectByExample(example);
        return list;
    }
}
